package Tasks;

import java.util.Iterator;

import SmartGrid.ExecutionEngine;

/**
 * Tries to shutdown the execution engine
 * If other tasks are running, wait, otherwise shutdown
 * @author jeffrey
 *
 */
public class ShutDownExecutionEngine extends MyRunnable{

	@Override
	public synchronized void run()
	{
		if(super.haltExecution()) return;
		if(ExecutionEngine.tasksRunning == 0)
		{
			ExecutionEngine.engine.shutdown();
			System.out.println("Execution Engine shut down");
		}
		else
		{
			System.out.println("Waiting on " + ExecutionEngine.tasksRunning + " tasks to shutdown execution engine...");
			Iterator<Runnable> iter = ExecutionEngine.futures.keySet().iterator();
			while(iter.hasNext())
			{
				Runnable r = iter.next();
				System.out.println(r.getClass());
			}
		}
	}
	
}
